<template>
	<view class="cu-list menu-avatar" style="height: 100vh;">
		<view class="cu-item" v-for="(item,index) in datas" :key="index" @click="handle(item)">
			<view class="cu-avatar round lg">
				<view class="img">
					<image :src="item.icon" mode="" class="img"></image>
				</view>
			</view>
			<view class="content">
				<view class="text-grey">{{item.name}}</view>
				<view class="text-gray text-sm flex">
					<view class="text-cut">
						<text class="text-red  "></text>
						{{item.info}}
					</view>
				</view>
			</view>
			<view class="action">
				<view class="text-grey text-xs">{{item.price}}</view>
				<text class="cuIcon-attentionfill margin-lr-xs"></text> {{item.number}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				datas: []
			}
		},
		methods: {
			async getData() {
				const res = await this.$https.get('/rest/Hero')
				this.datas = res.data
				this.datas.sort(this.compare("number", false))
				console.log(this.data, 'zhubinai')
			},
			compare(property, desc) {
				return function(a, b) {
					var value1 = a[property];
					var value2 = b[property];
					if (desc == true) {
						// 升序排列
						return value1 - value2;
					} else {
						// 降序排列
						return value2 - value1;
					}
				}
			},
			handle(item) {
				console.log(';213', item._id)
				const dataurl = 'rank'
				uni.navigateTo({ //成功后跳转到小程序首页，由于没得界面，我就屏蔽了。
					url: `/pages/cover/cards?id=${item._id}&&dataurl=${dataurl}`,
					success: function(res) {},
					fail: function(res) {
						console.log(';21123213', res)
					}
				});
			}
		},
		created() {
			this.getData()
		}
	}
</script>

<style lang="scss" scoped>
	.img {
		width: 50px;
		height: 50px;
		border-radius: 50%;
		background-size: cover;
		object-fit: cover;
		object-position: cover;
	}
</style>
